package com.concurrent.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author: zhouyang
 * @descrpition: 相当于Future的封装类 更加强大
 * @time: 2019-05-10 10:19
 */
@Slf4j
public class FutureTaskTest {
    public static void main(String[] args) throws Exception {
        FutureTask<String> futureTask = new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                log.info("my callable...");
                Thread.sleep(3000);
                return "okay";
            }
        });

        new Thread(futureTask).start();
        log.info("doing something...");
        Thread.sleep(1000);
        String result = futureTask.get();
        log.info("result:{}",result);
    }
}
